# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=p7zip
pkgver=9.38.1
pkgrel=1
pkgdesc='Command-line version of the 7zip compressed file archiver'
url='http://p7zip.sourceforge.net/'
license=('GPL' 'custom')
arch=('i686' 'x86_64')
depends=('gcc-libs' 'bash')
makedepends=('nasm')
groups=('compression')
options=('emptydirs')
source=("http://downloads.sourceforge.net/project/${pkgname}/${pkgname}/${pkgver}/${pkgname}_${pkgver}_src_all.tar.bz2"
        01_makefile_9.20.1.patch
        02_man_9.20.1.patch
        03_respect-umask-partial_9.20.1.patch
        10-const-ref-init.patch
        p7zip-9.20.1-1.src.patch)
sha1sums=('6b1eccf272d8b141a94758f80727ae633568ba69'
          'd59132544520e57647a6267e0777422bd305594f'
          'd071a69f00886d56e6546257715c9201547d4709'
          'b0ba244d6e59e348b0bc809e7ec2da1178c58744'
          '1bea51a933782205ff9143e6124525a532e3d546'
          '5d10264e9df45a49b96592c2307b410207b4075f')

options=('!makeflags')

prepare() {
  cd "${srcdir}/${pkgname}_${pkgver}"
  
  patch -p1 -i ${srcdir}/01_makefile_9.20.1.patch
  patch -p1 -i ${srcdir}/02_man_9.20.1.patch
  patch -p1 -i ${srcdir}/03_respect-umask-partial_9.20.1.patch
  patch -p1 -i ${srcdir}/10-const-ref-init.patch
  patch -p1 -i ${srcdir}/p7zip-9.20.1-1.src.patch
  
  [[ $CARCH = x86_64 ]] \
    && cp makefile.cygwin makefile.machine \
    || cp makefile.cygwin_asm makefile.machine

  rm GUI/kde4/p7zip_compress.desktop # FS#43766
}

build() {
  cd "${srcdir}/${pkgname}_${pkgver}"
  make all3 OPTFLAGS="${CXXFLAGS}"
}

check() {
  cd "${srcdir}/${pkgname}_${pkgver}"
  make test
  make test_7z
  make test_7zr
}

package() {
  cd "${srcdir}/${pkgname}_${pkgver}"
  
  #local sedexp1="s,^DEST_DIR=.*\$,DEST_DIR=${D},";
  #local sedexp2="s,^EXEEXT=.*\$,EXEEXT=.exe,";

  #mv -f install.sh install.sh.orig
  #cat install.sh.orig | sed -e "$sedexp1" -e "$sedexp2" > ./install.sh
  #chmod +x install.sh
  #./install.sh
  
  make install \
    DEST_DIR="${pkgdir}" \
    DEST_HOME="/usr" \
    DEST_MAN="/usr/share/man"

  # Licenses
  #install -d "${pkgdir}"/usr/share/licenses/p7zip
  #ln -s -t "${pkgdir}"/usr/share/licenses/p7zip \
  #  /usr/share/doc/p7zip/DOCS/License.txt \
  #  /usr/share/doc/p7zip/DOCS/unRarLicense.txt
  
  #cp contrib/gzip-like_CLI_wrapper_for_7z/README ${B}/p7zip-script.README
  #dodoc p7zip-script.README

  install -Dm755 contrib/gzip-like_CLI_wrapper_for_7z/p7zip ${pkgdir}/usr/bin/p7zip
  install -Dm644 contrib/gzip-like_CLI_wrapper_for_7z/man1/p7zip.1 ${pkgdir}/usr/share/man/man1/p7zip.1

  chmod -R a+r,u+w,a+X "${pkgdir}/usr"
}
